2024年3月9日 星期六

由 sensitivity 和 specificity 計算 post-test probability

分別用三種不同的網站界面呈現

1. Google Colab

https://colab.research.google.com/drive/1Sgs3iz5MzLmH3PPEVOai3tLCj1PDdOSh?usp=sharing


2. R shiny

https://3g01q7-chi0pan-hsieh.shinyapps.io/mywork2/


3. Python flask

https://goodmed.pythonanywhere.com/


Using R shiny to publish in a website

In Ubuntu 20.04, How can I use R Shiny to view a math function plot on a web page? function: y = x^2

ChatGPT

ChatGPT

To view a math function plot, such as y=x^2, on a web page using R Shiny in Ubuntu 20.04, follow these steps. I'll guide you through installing R, the necessary packages, and creating a basic Shiny app to display the plot of y=x^2

Step 1: Install R

Ubuntu 20.04 may not come with R pre-installed, so you'll need to install it. Open a terminal and run:

sudo apt update
sudo apt install r-base

Step 2: Install R Packages

Once R is installed, you need to install the Shiny package and ggplot2 for plotting. Start R in the terminal:

R

Then, install the packages by running:

install.packages("shiny")
install.packages("ggplot2")

Step 3: Create Your Shiny App

Shiny apps consist of a UI (User Interface) definition and a server function. You'll create a basic app to plot y=x^2. Create a new directory for your Shiny app and then create two files within that directory: ui.R and server.R.

  1. ui.R: This file defines the layout and appearance of your app.

library(shiny)

# Define UI for application
ui <- fluidPage(
   
   # Application title
   titlePanel("Plot of y = x^2"),
   
   # Sidebar with a slider input for the range of x
   sidebarLayout(
      sidebarPanel(
         sliderInput("range",
                     "X Range:",
                     min = -10,
                     max = 10,
                     value = c(-10, 10))
      ),
      
      # Show a plot of the generated distribution
      mainPanel(
         plotOutput("distPlot")
      )
   )
)
  1. server.R: This file contains the server logic to generate the plot based on the input range.

library(shiny)
library(ggplot2)

# Define server logic
server <- function(input, output) {
   
   output$distPlot <- renderPlot({
      x <- seq(input$range[1], input$range[2], by = 0.1)
      y <- x ^ 2
      ggplot(data.frame(x, y), aes(x = x, y = y)) +
         geom_line() +
         labs(title = "Plot of y = x^2",
              x = "x",
              y = "y")
   })
}
  1. Run Your App: Go back to your R session in the terminal. Set your working directory to the folder containing your app, then run:

library(shiny)
runApp()

Shiny will start a web server and give you a URL to access your app. Open this URL in a web browser to see the plot of y=x2 with the ability to adjust the range of xxx via a slider.

This is a simple example to get you started. Shiny is very flexible, allowing you to build highly interactive web applications. You can explore more features and capabilities of Shiny and ggplot2 to enhance your app.

Anonymous

how to show the above in a internet webpage?

ChatGPT

ChatGPT

To display a Shiny app on an internet webpage accessible to others, you would typically need to deploy the app to a server. There are a few common ways to do this:

1. ShinyApps.io

ShinyApps.io is a platform provided by RStudio for hosting Shiny applications. It's the easiest way to get started with deploying Shiny apps. Here's how you can do it:

  1. Install and Load the rsconnect Package: First, you need to install and load the rsconnect package in R, which is used for deploying applications to ShinyApps.io.

    install.packages("rsconnect")
    library(rsconnect)
  2. Set Up an Account on ShinyApps.io: If you haven't already, go to shinyapps.io and set up an account. After setting up your account, you'll find instructions to authorize your R session to deploy apps to your ShinyApps.io account.

  3. Deploy Your App: Use the deployApp function from the rsconnect package. Navigate to your app directory in R (using setwd) and then deploy your app.

    deployApp()

After deployment, you'll be given a URL where your app is hosted and can be accessed by anyone on the internet.

用 R shiny 發表動態圖在網站

用 Windows 下的 R 4.2.2 測試成功。

成品:

https://3g01q7-chi0pan-hsieh.shinyapps.io/mywork/

https://3g01q7-chi0pan-hsieh.shinyapps.io/mywork2/