Is there anything like R shiny in the typescript ecosystem?
- User
Is there anything like R shiny in the typescript ecosystem?
Assistant
Yes, there are several TypeScript/JavaScript alternatives to R Shiny for building interactive data applications:
Streamlit (via Pyodide) - While Streamlit is primarily Python-based, you can run it in the browser using Pyodide, and integrate TypeScript components. However, this isn't a pure TypeScript solution.
Observable Framework - This is probably the closest equivalent. It's a static site generator for data apps that supports TypeScript, with reactive updates and built-in data visualization capabilities. It's created by the team behind D3.js.
Dash (via Dash.js) - Plotly's Dash has JavaScript/TypeScript bindings, though the Python version is more mature. You can build interactive dashboards with reactive components.
Panel.js - A TypeScript port of Panel (Python), though still in early development.
Custom solutions using:
- Next.js + data visualization libraries (D3.js, Plotly.js, Chart.js)
- React + state management (Redux, Zustand) + visualization libraries
- Vue.js + visualization libraries
- Svelte + visualization libraries
For a more Shiny-like development experience, Observable Framework is worth exploring as it provides reactive data flow, built-in visualization support, and a focus on data applications. However, none of these options provide quite the same integrated experience as R Shiny - you'll typically need to combine multiple libraries to achieve similar functionality.
The TypeScript ecosystem tends to favor more modular, "build-your-own" approaches rather than monolithic frameworks like Shiny.
- User
Is RShiny also good to persist data somehow. So to enter data via a form and then save it somewhere in a text file on the server or in a database?
Assistant
Yes, R Shiny can handle data persistence, though it requires some additional setup. Here are the common approaches:
File-based storage:
- CSV/text files using
write.csv()orreadr::write_csv() - RDS files using
saveRDS()/readRDS() - Excel files using packages like
openxlsx
Database storage:
- SQLite - Great for single-user or light multi-user apps, no server setup needed
- PostgreSQL/MySQL - For production apps with multiple concurrent users
- MongoDB - For document-based storage
- Use packages like
DBI,RSQLite,RPostgres,RMySQL
Cloud storage:
- AWS S3 buckets
- Google Sheets (via
googlesheets4) - Dropbox (via
rdrop2)
Important considerations:
-
Concurrency - File-based storage can have issues with multiple users writing simultaneously. Databases handle this better.
-
Deployment environment - Free hosting like shinyapps.io has limitations on persistent storage. You may need Shiny Server Pro or custom hosting.
-
Security - Be careful with user inputs to prevent SQL injection (use parameterized queries) and validate all data.
Here's a simple example pattern:
# In server function observeEvent(input$submit, { new_data <- data.frame( name = input$name, value = input$value, timestamp = Sys.time() ) # File approach write.csv(new_data, "data.csv", append = TRUE) # Database approach con <- dbConnect(RSQLite::SQLite(), "app.db") dbWriteTable(con, "responses", new_data, append = TRUE) dbDisconnect(con) })For production apps, databases are generally preferred over file storage for reliability and concurrent access.
- CSV/text files using
- User
Is there a way to just write HTML and Javascript or Typescript to create an application. But then allow the JS to run "serverside" code like writing to a database or textfile? Or do I need a backend plus frontend to do this? It's just for localhost projects. I know of the implications this would have in a production app
Assistant
Yes, there are several ways to write HTML/JavaScript/TypeScript applications that can execute "server-side" operations like file system access or database writes, especially for localhost projects:
1. Electron
- Build desktop apps with web technologies
- Full Node.js API access (file system, databases, etc.)
- Your JavaScript runs with full system permissions
- Perfect for localhost/desktop applications
2. Tauri
- Similar to Electron but lighter weight
- Uses system webview instead of bundling Chromium
- Write frontend in HTML/JS/TS, backend in Rust
- Can expose Rust functions to JavaScript
3. Node.js with a simple HTTP server
- Create a single file that serves HTML and handles API routes:
const express = require('express'); const fs = require('fs'); const app = express(); app.get('/', (req, res) => { res.send(` <html> <button onclick="saveData()">Save</button> <script> async function saveData() { await fetch('/api/save', { method: 'POST' }); } </script> </html> `); }); app.post('/api/save', (req, res) => { fs.writeFileSync('data.txt', 'Hello World'); res.send('Saved!'); }); app.listen(3000);4. Deno
- Similar to Node.js but with built-in TypeScript support
- More secure by default but you can grant permissions
- Can serve HTML and handle file/database operations
5. Bun
- Fast all-in-one JavaScript runtime
- Built-in SQLite support
- Can serve HTTP and handle file operations in the same script
6. Local development servers with API routes
- Vite, Parcel, or webpack dev servers can be configured with API middleware
- Next.js API routes (even for static sites in dev mode)
- SvelteKit endpoints
For the simplest localhost setup, I'd recommend either:
- Electron if you want a desktop app experience
- A simple Node.js/Express server if you're fine with a browser interface
- Bun for the most modern, all-in-one solution with minimal setup
These approaches let you write your server logic and client code in the same language/project without needing a separate backend.
- User
I learned web development. So I know how to create a fullstack app. I explicitly do not want to define an API for the frontend and backend to communicate like you suggested with node. Or have I understood this wrong?
Assistant
Ah, I understand now! You want something more like PHP or classic ASP where your server-side code is directly embedded/integrated with your HTML, without explicit API endpoints. Here are some modern options:
1. HTMX + Any Backend
- Write server-side code that returns HTML fragments
- No JSON APIs, no client-side state management
- Your server functions return HTML directly
<button hx-post="/save-data" hx-swap="outerHTML"> Save </button>2. Astro with Server-Side Rendering
- Mix static HTML with server-side TypeScript/JavaScript
- Server code runs at request time:
--- // This runs on the server if (Astro.request.method === "POST") { await fs.writeFile("data.txt", "content"); } --- <form method="POST"> <button>Save</button> </form>3. Fresh (Deno framework)
- Islands architecture with server-side code
- No build step, TypeScript by default
- Server handlers colocated with components
4. PHP-style JavaScript with Bun
- Bun is working on
.bun.tsfiles that work like PHP files - Mix HTML with server-side TypeScript in the same file
5. LiveView-style frameworks
- LiveViewJS - Phoenix LiveView but for Node.js
- Server manages all state, sends HTML diffs over WebSocket
- No frontend/backend separation
6. Qwik City
- Resumable framework where server and client code is seamlessly integrated
- Write functions that run on the server but are called like regular functions
For your use case, I'd particularly recommend looking at HTMX with a simple server, or Fresh if you want a more integrated TypeScript experience. These approaches eliminate the traditional frontend/backend API boundary.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.